package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.OpenpayInfoMapper;
import com.xyy.saas.payment.dao.model.OpenpayInfo;
import com.xyy.saas.payment.service.OpenpayInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;

@Service
public class OpenpayInfoServiceImpl implements OpenpayInfoService {
    @Resource
    private OpenpayInfoMapper openpayInfoMapper;

    @Override
    public int insert(OpenpayInfo record) {
        return openpayInfoMapper.insert(record);
    }

    @Override
    public int updateByPrimaryKeySelective(OpenpayInfo record) {
        return openpayInfoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<OpenpayInfo> queryUserInfoByAccountId(String accountId, Long thirdUserInfoId) {
        return openpayInfoMapper.queryUserInfoByAccountId(accountId, thirdUserInfoId);
    }

    @Override
    public List<OpenpayInfo> queryByStatus(Integer status, Integer offset, Integer limit) {
        return openpayInfoMapper.queryByStatus(status, offset, limit);
    }

    @Override
    public int updateStatusByPowerId(OpenpayInfo record) {
        if(record == null) {
            throw new RuntimeException("record is null!");
        }

        if(StringUtils.isEmpty(record.getAccountId())) {
            throw new RuntimeException("accountId is null!");
        }

        if(StringUtils.isEmpty(record.getThirdUserInfoId())) {
            throw new RuntimeException("thirdUserInfoId is null!");
        }

        if(StringUtils.isEmpty(record.getPowerId())) {
            throw new RuntimeException("powerId is null!");
        }

        return openpayInfoMapper.updateStatusByPowerId(record);
    }

    @Override
    public int updateStatusWhereOpening(OpenpayInfo record) {
        if(record == null) {
            throw new RuntimeException("record is null!");
        }

        if(StringUtils.isEmpty(record.getAccountId())) {
            throw new RuntimeException("accountId is null!");
        }

        if(StringUtils.isEmpty(record.getThirdUserInfoId())) {
            throw new RuntimeException("thirdUserInfoId is null!");
        }

        if(StringUtils.isEmpty(record.getPowerId())) {
            throw new RuntimeException("powerId is null!");
        }

        if(StringUtils.isEmpty(record.getVersion())) {
            throw new RuntimeException("version status is null!");
        }

        return openpayInfoMapper.updateStatusWhereOpening(record);
    }


}
